package com.xiaoyu.lanling.feature.chat.model.message

import `in`.srain.cube.util.LocalDisplay
import com.xiaoyu.base.image.ImageLoadInfo

internal object ChatImageSizer {

    private val MAX_SIZE: Int = LocalDisplay.dp2px(144f)
    private val MIN_SIZE: Int = LocalDisplay.dp2px(64f)

    fun getImageWidth(imageInfo: ImageLoadInfo): Int {
        val ratio = imageInfo.ratio
        return when {
            ratio < 0.4 -> {
                MIN_SIZE
            }
            ratio >= 1.0 -> {
                MAX_SIZE
            }
            else -> {
                (ratio * MAX_SIZE).toInt()
            }
        }
    }

    fun getImageHeight(imageInfo: ImageLoadInfo): Int {
        val ratio = imageInfo.ratio
        return when {
            ratio <= 1.0 -> {
                MAX_SIZE
            }
            ratio > 2.5 -> {
                MIN_SIZE
            }
            else -> {
                (MAX_SIZE / ratio).toInt()
            }
        }
    }
}